package com.sanjiahantang.youjiarole.module.common.views.impl;

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.sanjiahantang.uilibrary.utils.Utils;
import com.sanjiahantang.youjiarole.R;
import com.sanjiahantang.youjiarole.base.BaseMvpActivity;
import com.sanjiahantang.youjiarole.base.BaseView;
import com.sanjiahantang.youjiarole.config.ConfigValue;
import com.sanjiahantang.youjiarole.config.SPConfig;
import com.sanjiahantang.youjiarole.http.BaseDelegate;
import com.sanjiahantang.youjiarole.http.OkHttpClientManager;
import com.sanjiahantang.youjiarole.module.common.beans.DataBean;
import com.sanjiahantang.youjiarole.module.common.presenters.MeAccountPresenter;
import com.sanjiahantang.youjiarole.module.common.views.MeAccountView;
import com.sanjiahantang.youjiarole.module.money.views.impl.MeWithdrawalsActivity;
import com.sanjiahantang.youjiarole.utils.CheckUtil;
import com.sanjiahantang.youjiarole.utils.SPUtils;
import com.squareup.okhttp.Request;

import java.util.HashMap;
import java.util.Map;


/**
 * 我的账户
 * Created by admin on 2017/10/28.
 */

public class MeAccountActivity extends BaseMvpActivity<MeAccountView, MeAccountPresenter> implements MeAccountView, View.OnClickListener {
    TextView title,txtmoney,btn_tixian;
    View fl_Left;

    @Override
    public MeAccountPresenter initPresenter() {
        return new MeAccountPresenter();
    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_me_account);
        fl_Left = findViewById(R.id.fl_Left);
        fl_Left.setOnClickListener(this);
        title = (TextView) findViewById(R.id.title);
        findViewById(R.id.btn_tixian).setOnClickListener(this);
        findViewById(R.id.flIcon3).setOnClickListener(this);
        txtmoney= (TextView) findViewById(R.id.txtmoney);

    }

    @Override
    public void initData() {
        showProgress();
        title.setText("我的账户");
        Map<String, Object> map = new HashMap<>();
        map.put(KEY_TOKEN, ConfigValue.DATA_KEY);
        map.put("userLogin", SPUtils.get(this, SPConfig.PHONE,""));
        OkHttpClientManager.postJson(this, ConfigValue.API_URL + "/money/phone/role/findMoneyInfo", map, new BaseDelegate.ResultCallback<DataBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                Utils.showToast($this,e.getMessage());
                hideProgress();
            }

            @Override
            public void onResponse(DataBean response, Object tag) {
                findViewById(R.id.txtmoney_title).setVisibility(View.VISIBLE);
                hideProgress();
                if(response != null && response.getData() != null && response.getData().getMoney()!=null){
                    txtmoney.setText(response.getData().getMoney());
                }else {
                    txtmoney.setText("0.00");
                }
            }
        });
    }
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.fl_Left:
                finish();
                break;
            case R.id.flIcon3:
                CheckUtil.checkTokenTimeOut($this, new OnLoadListener() {
                    @Override
                    public void onLoad(Object content) {
                        startActivity(new Intent($this,MeAccountDetailActivity.class));
                    }
                });

                break;
            case R.id.btn_tixian://yemian
                startActivity(new Intent($this,MeWithdrawalsActivity.class));
                break;
        }

    }

    @Override
    public void showProgress() {
        super.showProgress($this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        initData();
    }
}
